package com.cryptoneedle.center.ods.entity.ods;

import com.bubbles.engine.data.core.entity.BaseEntity;
import com.cryptoneedle.center.common.key.TableKey;
import com.cryptoneedle.center.common.key.TableMappingKey;
import jakarta.persistence.*;
import lombok.*;
import lombok.experimental.Accessors;
import org.hibernate.annotations.Comment;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

/**
 * <p>description: ODS-Mapping </p>
 *
 * @author CryptoNeedle
 * @date 2025-09-25
 */
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(schema = "public", name = "ods_mapping_table")
@IdClass(TableMappingKey.class)
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@Comment("ODS-Mapping")
public class OdsMappingTable extends BaseEntity {

    @Id
    @Column(length = 512)
    @Comment("所属 Catalog")
    private String catalogName;

    @Id
    @Column(length = 64)
    @Comment("所属 Database")
    private String databaseName;

    @Id
    @Column(length = 64)
    @Comment("表名称")
    private String tableName;

    @Id
    @Column(length = 512)
    @Comment("所属 Catalog")
    private String mappingCatalogName;

    @Id
    @Column(length = 64)
    @Comment("所属 Database")
    private String mappingDatabaseName;

    @Id
    @Column(length = 64)
    @Comment("表名称")
    private String mappingTableName;

    public TableMappingKey getKey() {
        return new TableMappingKey(this.catalogName, this.databaseName, this.tableName, this.mappingCatalogName, this.mappingDatabaseName, this.mappingTableName);
    }

    public String getKeyString() {
        return getKey().toString();
    }

    public TableKey getTableKey() {
        return new TableKey(this.catalogName, this.databaseName, this.tableName);
    }

    public String getTableKeyString() {
        return getTableKey().toString();
    }

    public TableKey getMappingKey() {
        return new TableKey(this.mappingCatalogName, this.mappingDatabaseName, this.mappingTableName);
    }

    public String getMappingKeyString() {
        return getMappingKey().toString();
    }
}